package com.ecelin.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ecelin.entity.BookInfo;
import com.ecelin.mapper.BookInfoMapper;
import com.ecelin.service.BookInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
@RequiredArgsConstructor
public class BookInfoController {

    private final BookInfoMapper bookInfoMapper;
    private final BookInfoService service;

    @GetMapping
    public List<BookInfo> getBookInfo(){
        List<BookInfo> bookInfos = bookInfoMapper.selectList(null);
        return bookInfos;
    }


    @PostMapping("add")
    public BookInfo add(@RequestBody BookInfo bookInfo){
        bookInfo.setId(IdWorker.getId(BookInfo.class));
        service.save(bookInfo);
        return bookInfo;
    }

}
